#include "ATMOS_DatabaseConnectionInfo.h"

#include <fstream>

using namespace ATMOS;

DatabaseConnectionInfo::DatabaseConnectionInfo() :
port( 0 )
{
}

DatabaseConnectionInfo::DatabaseConnectionInfo( const DatabaseConnectionInfo &src ) :
ip( src.ip ),
name( src.name ),
port( src.port ),
username( src.username ),
password( src.password )
{
}

DatabaseConnectionInfo::~DatabaseConnectionInfo()
{
}

void DatabaseConnectionInfo::saveToFile( const std::string &filename )
{
	std::ofstream file;

	file.open( filename.c_str() );
	if( !file.is_open() )
	{
		ATMOS_THROW_RT("failed to open file: " << filename);
	}

	file	<< ip << std::endl
			<< name << std::endl
			<< port << std::endl
			<< username << std::endl
			<< password << std::endl;

	file.close();
}

void DatabaseConnectionInfo::loadFromFile( const std::string &filename )
{
	std::ifstream file;

	file.open( filename.c_str() );
	if( !file.is_open() )
	{
		ATMOS_THROW_RT("failed to open file: " << filename);
	}

	file	>> ip
			>> name
			>> port
			>> username
			>> password;

	file.close();
}
